/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-28 19:07:40
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-01-31 11:22:17
 * @FilePath: \My-bolg\server\model\comment.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { DataTypes } = require('sequelize');
const sq = require('./db.js')
const moment = require('moment')
const comments = sq.define('comment', {
    content: {
        type: DataTypes.STRING,
        allowNull: false
    },
    type: {
        type: DataTypes.INTEGER,
        require: true,
        comment: "评论类型 1文章 2说说 3留言",
    },
    forid: {
        type:DataTypes.STRING,
        defaultValue: "",
        comment: "评论文章或者说说的id",
    },
    username:{
        type: DataTypes.STRING,
        require: true,
        comment: "用户名",
    },
    usersiteurl:{
        type: DataTypes.STRING,
        comment: "网站地址",
        defaultValue: "",
    },
    usercover:{
        type: DataTypes.STRING,
        
        comment: "用户头像",
        defaultValue: "",
    },
    fatherid: {
        type: DataTypes.STRING,
       
        comment: "父级顶层评论id",
        defaultValue: "",
    },
    fromid:{
        type: DataTypes.STRING,
        comment: "评论者id",
        defaultValue: "",
    },
    fromname:{
        type: DataTypes.STRING,
        
        comment: "评论者用户名",
        defaultValue: "",
    },
    commentstrs:{
        type: DataTypes.INTEGER,
        
        defaultValue: 0,
        comment: "评论点赞数量",
    },
    createdAt: {
        type: DataTypes.DATE,
        get() {
            return moment(this.getDataValue("createdAt")).format("YYYY-MM-DD HH:mm:ss")
        },
    },
    updatedAt: {
        type: DataTypes.DATE,
        get() {
            return moment(this.getDataValue("updatedAt")).format("YYYY-MM-DD HH:mm:ss")
        },
    },
}, {
    // 这是其他模型参数
    freezeTableName: true,
});
/*   comments.sync({ force: true }) */
module.exports = comments;